# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=automake1.15
pkgver=1.15
pkgrel=2
pkgdesc="A GNU tool for automatically creating Makefiles"
arch=('any')
license=('GPL')
url="http://www.gnu.org/software/automake"
groups=('base-devel')
depends=('perl' 'bash')
makedepends=('autoconf')
checkdepends=('dejagnu' 'python2')
install=automake.install
source=(ftp://ftp.gnu.org/gnu/automake/automake-${pkgver}.tar.xz{,.sig}
        automake1.15-documentation.patch
        automake-1.15-msys2.patch
        automake-1.15-perl-escape-curly-bracket.patch)
md5sums=('9a1ddb0e053474d9d1105cfe39b0c48d'
         'SKIP'
         'dc671559c3ab5ff1fe38bb6859cc6f01'
         'eb5d504185474b2de2163060c4df4d8d'
         '3d5bae907a03ee3d26d0f8a0ae649cc5')
replace=('automake')

prepare() {
  cd ${srcdir}/automake-${pkgver}

  patch -p1 -i ${srcdir}/automake1.15-documentation.patch
  patch -p1 -i ${srcdir}/automake-1.15-msys2.patch
  patch -p1 -i ${srcdir}/automake-1.15-perl-escape-curly-bracket.patch
}

build() {
  cd ${srcdir}/automake-${pkgver}
  ./configure --prefix=/usr
  make

  (cd doc && makeinfo -I ${srcdir}/automake-${pkgver}/doc -o automake1.15.info automake.texi)
  (cd doc && makeinfo -I ${srcdir}/automake-${pkgver}/doc -o automake-history1.15.info automake-history.texi)
}

check() {
  cd ${srcdir}/automake-${pkgver}

  # expect 2 failures due to perl-5.18 incompatibility
  make -k check || true
}

package() {
  cd ${srcdir}/automake-${pkgver}
  make DESTDIR=${pkgdir} install

  mv ${pkgdir}/usr/share/aclocal/README ${pkgdir}/usr/share/aclocal/README.am15

  # install the 1.15 versioned info files
  for f in `find ${pkgdir}/usr/share/info -name "*.info*"` ; do
    rm -f ${f}
  done
  for f in `find ${srcdir}/automake-${pkgver} -name "*.info*"` ; do
    bf=`basename $f`
    cp $f ${pkgdir}/usr/share/info/
  done

  # remove the unversioned executables
  rm -f ${pkgdir}/usr/bin/automake ${pkgdir}/usr/bin/aclocal

  # remove the unversioned man pages
  rm -f ${pkgdir}/usr/share/man/man1/automake.1
  rm -f ${pkgdir}/usr/share/man/man1/aclocal.1

  # remove the unversioned info files
  rm -f ${pkgdir}/usr/share/info/automake.info*
  rm -f ${pkgdir}/usr/share/info/automake-history.info*

  rm -rf ${pkgdir}/usr/share/doc
}
